/**
 * 字典管理初始化
 */
var Employee = {
    id: "EmployeeTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Employee.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '名称', field: 'name', align: 'center', valign: 'middle', sortable: true},
        {title: '详情', field: 'phone', align: 'center', valign: 'middle', sortable: true},
        {title: '地址', field: 'area', align: 'center', valign: 'middle', sortable: true},
        {title: '银行', field: 'bank_type', align: 'center', valign: 'middle', sortable: true}];
};


/**
 * 点击添加字典
 */
Employee.openAddEmployee = function () {
    var index = layer.open({
        type: 2,
        title: '添加字典',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/employee/employee_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
Employee.openEmployeeDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '字典详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/employee/employee_edit/' + Employee.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
Employee.delete = function () {
    if (this.check()) {

        var operation = function(){
            var ajax = new $ax(Feng.ctxPath + "/employee/delete", function (data) {
                Feng.success("删除成功!");
                Employee.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("employeeId", Employee.seItem.id);
            ajax.start();
        };

        Feng.confirm("是否刪除字典 " + Employee.seItem.name + "?", operation);
    }
};

/**
 * 查询员工
 */
Employee.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Employee.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Employee.initColumn();
    var table = new BSTable(Employee.id, "/employee/list", defaultColunms);
    table.setPaginationType("client");
    Employee.table = table.init();
});
